package utils

import (
	"context"
	"fmt"
	"net/http"
	"strings"
	"time"

	"github.com/mozillazg/go-cos"
)

var CosClient *cos.Client

func InitCos() error {
	b, err := cos.NewBaseURL("https://leyoubox-1257643903.cos.ap-beijing.myqcloud.com")
	CosClient = cos.NewClient(b, &http.Client{
		Transport: &cos.AuthorizationTransport{
			SecretID:  "AKIDEJAoERKBl8HCtMsdR2PZWGkyve8Ne5Xj",
			SecretKey: "3rOkupUu50f4E8mAlALJ4bv211tWt0sV",
		},
	})
	return err
}

func TestCos() {
	fileName := fmt.Sprintf("%d.txt", time.Now().Unix())

	_, err := CosClient.Object.Put(context.Background(), fileName, strings.NewReader(string("hello, world")), nil)
	fmt.Printf("err:%+v\n", err)
}
